<template>
  <view class="content b-t">
	<nav-bar   fontColor="#FFFFFF" title="发票管理"></nav-bar>
    <view class="list b-b" v-for="(item, index) in addressList" :key="index">
      <view class="wrapper" @click="handleCheckAddress(item)">
        <view class="u-box">
          <text class="name">{{ item.name }}</text>
          <text class="mobile">{{ item.phone }}</text>
        </view>
        <view class="address-box">
          <text v-if="item.defaultStatus == 1" class="tag">默认</text>
          <text class="address">{{ item.provinceName }}-{{ item.cityName }}-{{ item.districtName }}-{{ item.address }}</text>
        </view>
      </view>
      <view class="" style="display: flex;flex-direction: row;width: 100%;justify-content: flex-end;">
        <view class="" style="width: 20%;display: flex;align-items: center;justify-content: center;" @click="handleEdit(item.id)">
          <text class="yticon icon-bianji"></text>
          <text style="font-size: 30upx;margin-left: 10upx;">编辑</text>
        </view>
        <view class="" style="width: 20%;display: flex;align-items: center;justify-content: center;" @click="handleRemove(item.id)">
          <text class="yticon icon-iconfontshanchu1"></text>
          <text style="font-size: 30upx;">删除</text>
        </view>
      </view>
    </view>
    <button type="primary" class="add-btn" @click="handleAdd">新增</button>
  </view>
</template>

<script>

export default {
  data() {
    return {
      addressList: []
    };
  },
  onLoad(option) {
    
  },
  onShow() {
    
  },
  methods: {
    // 选择地址
    handleCheckAddress(item) {
      // 微信小程序对上一页的地址信息特殊处理
      if (AppConfig.source == 1) {
        this.prePage().addressData = item;
        this.prePage().addressId = item.id;
        uni.navigateBack();
      }
    },
    handleAdd() {
      uni.navigateTo({
        url: `/pages/resource/ticketList`
      });
    },
    // 删除地址
    handleRemove(id) {
      this.$api.order.userAddress.remove(id).then(res => {
        if (res) {
          uni.showToast({
            title: '删除成功'
          });
          // this.getListAddress();
        } else {
          uni.showToast({
            title: '删除失败',
            icon: 'none'
          });
        }
      })
    },
    handleEdit(id) {
      uni.navigateTo({
        url: `/pages/order/address-form?id=${id}`
      });
    },
    //添加或修改成功之后回调
    refreshList(data, type) {
      // 添加或修改后事件，这里直接在最前面添加了一条数据，实际应用中直接刷新地址列表即可
      this.addressList.unshift(data);
      console.log(data, type);
    }
  }
};
</script>

<style lang="scss">
page {
  padding-bottom: 120upx;
}
.content {
  position: relative;
}
.list {
  display: flex;
  align-items: center;
  flex-direction: column;
  padding: 20upx;
  background: #fff;
  position: relative;
}
.wrapper {
  width: 100%;
  display: flex;
  flex-direction: column;
  flex: 1;
}
.address-box {
  display: flex;
  align-items: center;
  margin: 10upx 0;
  .tag {
    font-size: 24upx;
    margin-right: 10upx;
    background: #fffafb;
    border: 1px solid #ffb4c7;
    border-radius: 4upx;
    padding: 4upx 10upx;
    line-height: 1;
  }
  .address {
    font-size: 28upx;
  }
}
.u-box {
  font-size: 32upx;
  // margin-top: 16upx;
  .name {
    margin-right: 30upx;
  }
}
.icon-bianji {
  // display: flex;
  // align-items: center;
  // height: 80upx;
  font-size: 36upx;
  // padding-left: 30upx;
}
.add-btn-2 {
  position: fixed;
  left: 30upx;
  right: 30upx;
  bottom: 16upx;
  align-items: center;
  justify-content: center;
  width: 690upx;
  height: 80upx;
  font-size: 32upx;
  color: #CCCCCC;
  border-radius: 10upx;
}
.add-btn {
  position: fixed;
  left: 30upx;
  right: 30upx;
  bottom: 16upx;
  align-items: center;
  justify-content: center;
  width: 690upx;
  height: 80upx;
  font-size: 32upx;
  color: #fff;
  border-radius: 10upx;
}
</style>
